Skip to main content

Custom Storage Client

Overview

The StorageClient interface is designed to be implemented by platform-specific storage solutions, such as SQLite, ObjectBox, Custom Hardware or FileSystem. This interface allows the Mobile SDK to interact with the storage layer without being tied to a specific implementation.

This guide provides a demo implementation of in-memory client. This is useful for testing or development purposes, but it is not suitable for production use. But we can create a custom storage provider to persist data.

Implementing a Custom Storage Provider

App.tsx
class CustomStorageClient: StorageClient {

private var keyshareDaoSet: Set<ReconcileStoreDao> = []

func write(dao: ReconcileStoreDao) async {
if !keyshareDaoSet.insert(dao).inserted {
keyshareDaoSet.remove(dao)
keyshareDaoSet.insert(dao)
}
}

func read(key: String) async throws -> ReconcileStoreDao? {
return keyshareDaoSet.first { $0.keyId == key }
}
}